Ext.BLANK_IMAGE_URL = '../ext/resources/images/default/s.gif';

Ext.onReady(function(){

  Ext.QuickTips.init();
	function showSpinner(){
	    Ext.MessageBox.show({
           msg: '提示:数据正在导入中，请稍候...',
           progressText: '',
           width:300,
           wait:true,
           waitConfig: {interval:200},
           icon:'ext-mb-download'//custom class 
       });
	}
	
	
	function doJSON(stringData) {
		try {
			var jsonData = Ext.util.JSON.decode(stringData);
			Ext.MessageBox.alert('Success', jsonData.msg);
			
		}
		catch (err) {
			Ext.MessageBox.alert('ERROR', 'Could not decode ' + stringData);
		}
	}
   	function doAjax() {
   		Ext.Ajax.on('beforerequest', showSpinner, this);
		Ext.Ajax.request({
			url : 'importbasicdata.action' , 
			method: 'GET',
			success: function ( result, request) { 
				Ext.MessageBox.hide();
				doJSON(result.responseText);
			},
			failure: function ( result, request) { 
				Ext.MessageBox.alert('Failed', 'Successfully posted form: '+result.failure); 
			} 
		});
	} 	
	function importConfirm(btn, text){
       if(btn=='yes'){
       		doAjax();
       }
    }
   var action1 = new Ext.Action({
     text: '中文版',
     handler: function(){
         openNewWindow("CH/index.htm","中文版");
     },
     iconCls: 'bmenu'
 	});
   var action2 = new Ext.Action({
     text: '英文版',
     handler: function(){
         openNewWindow("EN/index.htm","英文版");
     },
     iconCls: 'bmenu'
 	});
    var p = new Ext.Panel({
        title: '基础数据',
        collapsible:true,
        renderTo: 'basic',
        width:400,
		autoheight:true,        
        frame:true,
		tools:[{
					id:'gear',
					qtip:'导入基础数据',
					handler:function(event,toolEl,panel){
						var msg='接下来将把基础数据重新导入到数据库中，这是一个耗时较长的工作，你确认执行操作么？';
						if(Ext.isIE){
							 Ext.MessageBox.confirm('Confirm',msg , importConfirm);
						}else{
							if(confirm(msg)){
								Ext.Ajax.request({
									url : 'importbasicdata.action' , 
									method: 'GET',
									success: function ( result, request) { 
											var stringData=result.responseText;
											var jsonData = Ext.util.JSON.decode(stringData);
											alert(jsonData.msg);
									},
									failure: function ( result, request) { 
										alert('Successfully posted form: '+result.failure); 
									} 
								});									
							}
						}
						 
					}
				}
		],        
        items:[
        	new Ext.Button(action1),
        	new Ext.Button(action2)
        ]
    });
  


});